// pages/jieshu/jieshu.js

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    bookcar: []
  },
  /**
   * 生命周期函数--监听页面加载
   */
  // 获得书籍信息
  onLoad: function (options) {
    const db = wx.cloud.database()
    db.collection("books").get({
      success: res => {
        this.setData({
          books: res.data
        })
      }, fail: err => {
        wx.showToast({
          icon: "none",
          title: '查询记录失败',
        })
      }
    })
  },
  comfirm: function (e) {
  const db = wx.cloud.database()//打开数据库连接
    let bookcar = e.detail.value
      this.add(db, bookcar)  //新增记录
  }, 
  add: function (db, bookcar) {
    db.collection("bookscaro").add({
      data: {
        name: 'name',
        author: 'author',
        words: 'words',
      }, success: res => {
        wx.showToast({
          title: '新增记录成功',
        })
      }, fail: err => {
        wx.showToast({
          title: '新增失败',
        })
      }
    })
  },
  adddetial:function(){
    wx.navigateTo({
      url: '../bookcar/bookcar',
    })
  }

})